{% extends "default/admin/include/innerBase.html" %}{% block mainer %}
<table id="catalogList" class="elementList">
	<thead><tr class="treetr" fold="0">
	    <th width="30px"></th><th width="42px"><div>顺序</div></th><th width="120px"><div>名称</div></th><th width="80px"><div>目录值</div></th>
    	<th width="90px"><div>所属栏目</div></th><th width="90px"><div>类型</div></th><th width="110px"><div>层级</div></th><th width="72px"><div>终极目录</div></th><th width="42px"><div>显示</div></th><th><div>操作</div></th>
    </tr></thead>
{% for e in catalogList %}{%if e.level.value == 10%}
    {% include site.theme|stringformat:"s/admin/include/element.html" with e=e etype='catalog' %}
    {% for e1 in catalogList %}{% if e1.level.value == 20 and e1.parent.value == e.id %}
    	{% include site.theme|stringformat:"s/admin/include/element.html" with e=e1 etype='catalog' foldid=e.id %}
    {%endif%}{% empty %}{% endfor %}
    {% if not e.islast.value %}<tr class="treetr"><td></td><td colspan="9"><span class="tree"></span><span class="addtree"><a href="javascript:addElement(20,{{e.id}});">添加子目录</a></span></tr>{%endif%}
{%endif%}{% empty %}{% endfor %}
	<tr id="addcatalog" class="treetr"><td></td><td colspan="9"><span class="addtree"><a href="javascript:addElement(10,-1);">添加目录</a></span></td></tr>
</table>
<div id="addtb" style="display:none;"><form><table class="formTable">{{catalogForm}}</table></form></div>
<script type="text/javascript">
function foldClick(id){
	var afold = $("#fold-"+id);
	if(afold.html()=='[-]'){
		afold.html('[+]');
		$("tr[fold='"+id+"']").hide();
	}else{
		afold.html('[-]');
		$("tr[fold='"+id+"']").show();
	}
}
function addElement(level,parent){
	formStr = "&level="+level+"&parent="+parent;
	var api = $.dialog({
		id:'addDlg', title:'添加参数',
		content: $('#addtb').html(),
		max: false, min: false, lock: true,
		init: function(){
			$('#id_level', this.DOM.content).val(level).attr('disabled',true);
			$('#id_parent', this.DOM.content).val(parent).attr('disabled',true);
			if(level==20){$('#id_islast', this.DOM.content).attr("checked",'true').attr('disabled',true);formStr+="&islast=on"}
		},
		okVal: '增加',
	    ok: function(){
	    	var thisDlg = this;
	    	$.post('/admin/add!Catalog.do', $('form',thisDlg.DOM.content).serialize()+formStr, 
    			function(data){
	    			try{
	    				if(data.flag){$.dialog.alert(data.msg, function(){thisDlg.close();thisDlg.reload();});}
     					else{$.dialog.alert(data.msg);}
	     			}catch(e){$.dialog.alert(data);}
      			},'json');
	    	return false;
	    },
	    cancel: true
	});
}
function editElement(id){
	formStr = '&_retType=json';
	var url = 'url:/admin/detailCatalog-'+id+'.html';
	var api = $.dialog({
		id:'editDlg', title:'编辑栏目',
		content: url,
		max: false, min: false, lock: true, width: '300px',
		init: function(){
			levelObj = $('#id_level', this.iwin.document.body);
			if(levelObj.val()==20){$('#id_islast', this.iwin.document.body).attr('disabled',true);formStr+="&islast=on"}
			formStr +=  "&level="+levelObj.val();
			levelObj.attr('disabled',true);
		},
		okVal: '编辑',
	    ok: function(){
	    	var thisDlg = this;
	    	$.post('/admin/edit!Catalog.do', $('form', thisDlg.iwin.document.body).serialize()+formStr, 
    			function(data){
      				if(data.flag){$.dialog.alert(data.msg, function(){thisDlg.close();thisDlg.reload();});}
      				else{$.dialog.alert(data.msg);}
      			},'json');
	    	return false;
	    },
	    cancel: true
	});
}
//ie中必须在文档加载完毕后才能执行函数，否则没有效果
$(function(){listHover();});
</script>
{% endblock %}